package com.chen10.cattle.common.enums.response;

import lombok.Getter;

@Getter
public enum ErrorEnum {

    // 成功
    SUCCESS(0, "操作成功"),

    // 系统级错误
    SYSTEM_ERROR(500, "系统内部错误"),
    INVALID_REQUEST(400, "请求无效或参数错误"),
    NOT_FOUND(404, "资源未找到"),
    MULTIPART_EXCEPTION(400, "当前请求不是一个有效的多部分请求，请检查您的上传格式"),

    // 用户认证和授权相关错误
    UNAUTHORIZED(401, "未经授权的操作，请先登录"),
    TOKEN_FORMAL_ERROR(401, "token格式错误"),
    TOKEN_INVALID(401, "token无效"),
    TOKEN_EXPIRED(401, "token已过期"),
    TOKEN_INVALID_OR_EXPIRED(401, "token无效或已过期，请重新登录"),

    PARAM_ERROR(1000,"参数错误"),
    PHONE_NUMBER_INVALID(1000, "手机号格式错误"),
    GENDER_INVALID(1000, "性别设置错误！"),
    SIGNATURE_INVALID(1000,"个性签名长度不能超过30个字符！" ),
    // 验证码相关错误
    VERIFICATION_CODE_EXPIRED(1001, "验证码已过期"),
    VERIFICATION_CODE_INVALID(1002, "验证码无效"),

    // 用户注册登录相关错误
    USERNAME_ALREADY_EXISTS (2001, "用户名已存在"),
    USER_NOT_FOUND(2002, "用户不存在"),
    PASSWORD_ERROR(2003, "密码错误"),
    ACCOUNT_DISABLED(2005, "账户已被禁用"),
    USERNAME_LENGTH_ERROR(2006,"用户名长度应在5-15位之间"),
    PASSWORD_INVALID(2007,"密码至少包含数字和字母，长度6到20"),
    PASSWORD_NOT_SAME(2008,"两次密码输入不一致"),
    AGREEMENT_NOT_AGREED (2009,"请同意用户协议"),
    PLEASE_ENTER_EMAIL_AND_PASSWORD(2010,"请输入邮箱和密码"),
    USER_NOT_FOUND_EMAIL_UNREGISTER(2011,"用户不存在，该邮箱未注册"),
    USER_STATUS_DISABLED(2012,"用户已被禁用"),
    USERNAME_CANT_EMPTY(2013, "用户名不能为空"),

    //邮箱相关错误
    EMAIL_INVALID(3001, "邮箱格式错误"),
    EMAIL_ALREADY_EXISTS(3002, "邮箱已被注册"),
    EMAIL_NOT_FOUND(3003, "邮箱未注册"),
    EMAIL_SEND_FAILED(3004, "邮件发送失败，请检查邮箱号或稍后再试"),
    EMAIL_CODE_ERROR(3005, "邮箱验证码错误或失效"),
    EMAIL_CODE_ALREADY_EXITED(3006,"请勿频繁请求验证码"),

    // 文件相关错误
    UPLOAD_AVATAR_FILE_NULL(4001,"上传的头像文件为空"),
    INVALID_IMAGE_FORMAT(4002, "无效的图片格式"),
    FILE_SIZE_EXCEED_LIMIT(4003, "文件大小超出限制"),
    UPLOAD_AVATAR_FAILED(4004,"上传头像失败"),
    DEFAULT_AVATAR_NOT_FOUND(4005, "默认头像未找到"),
    GET_AVATAR_FAILED(4005,"读取头像失败"),
    FILE_PATH_INVALID(4006,"文件路径无效"),
    FILENAME_NULL(4007,"文件名不能为空"),
    FILE_UPLOAD_ERROR(4008, "文件上传错误"),


    //好友相关错误,
    ALREADY_FRIEND(5001,"已经是好友"),
    REMOVE_ERROR_NOT_FRIEND_YET(5002, "删除好友失败：还不是好友"),
    EXIST_UNPROCESSED_REQUEST(5003, "等待对方处理请求，请勿重复发送"),
    HANDLE_FRIEND_REQUEST_ERROR(5004, "处理好友请求失败"),
    BLOCK_FRIEND_ERROR(5005, "拉黑好友失败"),
    FRIEND_NOT_ONLINE(5006,"好友不在线"),
    CANNOT_INVITE_SELF(5007,"不能邀请自己"),

    // 游戏相关错误
    FRIEND_IS_PLAYING(5008, "好友正在对战"),
    FRIEND_IS_INROOM(5009, "好友正在组队中"),

    ROOM_ALREADY_CREATED(5009,"创建房间失败：重复创建房间！" ),
    ROOM_NOT_EXIST(5010, "房间不存在！"),
    FIGHT_INVITE_EXPIRED(5011, "邀请已过期！"),
    ROOM_GAME_ALREADY_STARTED(5012, "加入房间失败，对局已开始！"),
    ROOM_ALREADY_FULL(5013, "加入房间失败，房间已满！"),
    USER_NOT_IN_ROOM(5014, "用户不在该房间中！"),
    FRIEND_NOT_IN_ROOM(5015,"好友不在房间！无法开始游戏！"),
    ROOM_FULL(5016, "房间已满！"),
    NOT_YOUR_TURN(5017, "当前不是你的回合！"),
    INVALID_MOVE(5018, "落子位置不合法"),
    UNKNOWN_AIMODE(5019, "未知的AI模式"),
    USER_IS_MATCHING(5020,"用户正在匹配中"),
    USER_IS_NOT_MATCHING(5021,"用户不在匹配中");

    private final int code;
    private final String message;

    ErrorEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String toString() {
        return "ErrorEnum{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }

    // 根据code查找对应的枚举项
    public static ErrorEnum fromCode(int code) {
        for (ErrorEnum error : ErrorEnum.values()) {
            if (error.getCode() == code) {
                return error;
            }
        }
        return null; // 或者抛出异常，根据需求决定
    }
}
